package cn.db101.kaoqinserver.controller;

import cn.db101.kaoqinserver.config.ApiResult;
import cn.db101.kaoqinserver.domain.Course;
import cn.db101.kaoqinserver.model.request.CourseParam;
import cn.db101.kaoqinserver.service.CourseService;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("v1/kaoqin/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @PostMapping("list")
    public ApiResult<?> list() {

        return ApiResult.ofSuccess(courseService.list());
    }

    @PostMapping("leaveList")
    public ApiResult<?> leaveList(@RequestBody CourseParam courseParam) {

        int loginId = Integer.parseInt(StpUtil.getLoginId().toString());
        courseParam.setUserId(loginId);
        return ApiResult.ofSuccess(courseService.leaveList(courseParam));
    }

    @PostMapping("checkList")
    public ApiResult<?> checkList(@RequestBody CourseParam courseParam) {

        return ApiResult.ofSuccess(courseService.leaveList(courseParam));
    }

    @PostMapping("page")
    public ApiResult<?> page(@RequestBody CourseParam courseParam) {

        return ApiResult.ofSuccess(courseService.page(courseParam));
    }

    @PostMapping("pullCourse")
    public ApiResult<?> pullCourse() {

        return ApiResult.ofSuccess(courseService.pullCourse());
    }

    @PostMapping("selectOne")
    public ApiResult<?> selectOne(@RequestBody Course course) {

        return ApiResult.ofSuccess(courseService.selectOne(course));
    }

    @PostMapping("update")
    public ApiResult<?> update(@RequestBody Course course) {

        courseService.update(course);
        return ApiResult.ofSuccess();
    }

    @PostMapping("create")
    public ApiResult<?> create(@RequestBody Course course) {

        courseService.create(course);
        return ApiResult.ofSuccess();
    }

    @PostMapping("location/update")
    public ApiResult<?> updateLocation(@RequestBody Course course) {

        courseService.updateLocation(course);
        return ApiResult.ofSuccess();
    }



}
